package cn.jksoft.businessclient.ui.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.yokeyword.indexablelistview.IndexBarAdapter;

import butterknife.Bind;
import butterknife.ButterKnife;
import cn.jksoft.businessclient.R;
import cn.jksoft.businessclient.bean.CustomerEntity;

/**
 * Created by RogersHuang on 16/4/8.
 */
public class CustomerSelectAdapter extends IndexBarAdapter<CustomerEntity.StoreCustomerListBean> {
    private Context mContext;

    public CustomerSelectAdapter(Context context) {
        mContext = context;
    }

    @Override
    protected TextView onCreateTitleViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_tv_title_customer, parent, false);
        return (TextView) view.findViewById(R.id.tv_title);
    }

    @Override
    protected ViewHolder onCreateViewHolder(ViewGroup parent) {
        // 创建 Item布局
        View view = LayoutInflater.from(mContext).inflate(R.layout.customer_list_item, parent, false);
        return new CustomerViewHolder(view);
    }

    @Override
    protected void onBindViewHolder(ViewHolder holder, CustomerEntity.StoreCustomerListBean entity) {
        // 为Item布局绑定数据
        CustomerViewHolder viewHolder= (CustomerViewHolder) holder;
        viewHolder.tvCarNumber.setText(entity.getCAR_PLATE_NUM());
        viewHolder.tvName.setText(entity.getCUSTOMER_NAME().replace("#",""));
        viewHolder.tvMember.setText(entity.getMEMBER_TYPE_NAME());

    }

    // ViewHolder需要继承IndexBarAdapter.ViewHolder
    class CustomerViewHolder extends IndexBarAdapter.ViewHolder {
        @Bind(R.id.tv_car_number)
        TextView tvCarNumber;
        @Bind(R.id.tv_name)
        TextView tvName;
        @Bind(R.id.tv_member)
        TextView tvMember;
        public CustomerViewHolder(View view) {
            super(view);
            ButterKnife.bind(this,view);
        }
    }
}
